const express=require("express");
//引入连接池模块
const pool=require("../pool.js")
var router=express.Router();
//用户登录
router.post("/login",(req,res)=>{
	var $phone=req.body.uphone;
	var $upwd=req.body.upwd;
	if(!$phone){
		res.send("手机号码不能为空")
		return;
	}
	if(!$upwd){
		res.send("密码不能为空")
		return;
	}
	var sql="select * from user where uphone=? and upwd=?";
	pool.query(sql,[$phone,$upwd],(err,result)=>{
		if(err)throw err
		console.log(result)
		if(result.length>0){
			res.send(result[0].name)
				console.log(result)
		}else{
			res.send("0")	
		}
	})
})
//注册用户
router.post("/reg",(req,res)=>{
	var $uname=req.body.uname
	var $phone=req.body.phone
	var $pwd=req.body.pwd
	console.log(req.body)
	var sql="insert into user set ?"
	pool.query(sql,[req.body],(err,result)=>{
		if(err)throw err
		if(result.affectedRows>0){
			res.send("1")
		}
	})
})
//导出路由
module.exports=router;
